package com.hjli.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hjli.model.TagInfo;
import com.hjli.model.TypeInfo;
import com.hjli.service.impl.TagService;

@Controller
@RequestMapping("sys/tag")
public class TagController {

	@Resource
	TagService tagService;
	/**
	 * 注释：文章标签保存，返回值 Map<String,Object>
	 * 时间：2017-07-10 
	 * 作者：Haojie Li
	 * */
	@RequestMapping("save")
	public @ResponseBody Map<String,Object> save(HttpServletRequest request ,HttpServletResponse response){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		//类型名称
		if(request.getParameter("tagName")==null){
			resultMap.put("result", "标签名称不能为空！");
		}else  if(request.getParameter("tagName").toString()==""){
			resultMap.put("result", "标签名称不能为空！");
		}else{
			
			String tagName = request.getParameter("tagName").toString();
			TagInfo tagInfo = new TagInfo();
			tagInfo.settName(tagName);
			
			//录入数据库
			if(tagService.insertSelective(tagInfo)==1){
				resultMap.put("result", "success");
			}else{
				resultMap.put("result", "添加失败！");
			}
		}
		return resultMap;
	}
	
	/**
	 * 注释：标签列表，返回值 Map<String,Object>
	 * 时间：2017-07-10 
	 * 作者：Haojie Li
	 * */
	@RequestMapping("all_list")
	public @ResponseBody Map<String,Object> all_list(HttpServletRequest request ,HttpServletResponse response){
		Map<String,Object> resultMap = new HashMap<String,Object>();
//		List<TagInfo> list = tagService.selectByPrimaryKey(1);
		List<TagInfo> list = tagService.tagInfoAll();
		resultMap.put("result", list);
		return resultMap;
	}
}
